home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Interfaces / CIncludes / MixedMode.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-11  |  10.6 KB  |  370 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        MixedMode.h
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a3  ETO #16, MPW prerelease.  Friday, November 11, 1994. 
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. */
  16.  
  17. #ifndef __MIXEDMODE__
  18. #define __MIXEDMODE__
  19.  
  20.  
  21. #ifndef __TYPES__
  22. #include <Types.h>
  23. #endif
  24. /*    #include <ConditionalMacros.h>                                */
  25.  
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29.  
  30. #if GENERATINGPOWERPC
  31. #pragma options align=mac68k
  32. #endif
  33.  
  34. #ifdef __CFM68K__
  35. #pragma lib_export on
  36. #endif
  37.  
  38.  
  39. enum {
  40.     kRoutineDescriptorVersion    = 7
  41. };
  42.  
  43. /* MixedModeMagic Magic Cookie/Trap number */
  44. enum {
  45.     _MixedModeMagic                = 0xAAFE
  46. };
  47.  
  48. /* Calling Conventions */
  49. typedef unsigned short CallingConventionType;
  50.  
  51.  
  52. enum {
  53.     kPascalStackBased            = (CallingConventionType)0,
  54.     kCStackBased                = (CallingConventionType)1,
  55.     kRegisterBased                = (CallingConventionType)2,
  56.     kD0DispatchedPascalStackBased = (CallingConventionType)8,
  57.     kD1DispatchedPascalStackBased = (CallingConventionType)12,
  58.     kD0DispatchedCStackBased    = (CallingConventionType)9,
  59.     kStackDispatchedPascalStackBased = (CallingConventionType)14,
  60.     kThinkCStackBased            = (CallingConventionType)5
  61. };
  62.  
  63. /* ISA Types */
  64. typedef SInt8 ISAType;
  65.  
  66.  
  67. enum {
  68.     kM68kISA                    = (ISAType)0,
  69.     kPowerPCISA                    = (ISAType)1
  70. };
  71.  
  72. /* RTA Types */
  73. typedef SInt8 RTAType;
  74.  
  75.  
  76. enum {
  77.     kOld68kRTA                    = (RTAType)(0 << 4),
  78.     kPowerPCRTA                    = (RTAType)(0 << 4),
  79.     kCFM68kRTA                    = (RTAType)(1 << 4)
  80. };
  81.  
  82. #if GENERATINGPOWERPC
  83. #define GetCurrentISA() ((ISAType) kPowerPCISA)
  84. #define GetCurrentRTA() ((RTAType) kPowerPCRTA)
  85. #else
  86. #define GetCurrentISA() ((ISAType) kM68kISA)
  87. #if GENERATINGCFM
  88. #define GetCurrentRTA() ((RTAType) kCFM68kRTA)
  89. #else
  90. #define GetCurrentRTA() ((RTAType) kOld68kRTA)
  91. #endif
  92. #endif
  93. #define GetCurrentArchitecture() (GetCurrentISA() | GetCurrentRTA())
  94. enum {
  95.     kRegisterD0                    = 0,
  96.     kRegisterD1                    = 1,
  97.     kRegisterD2                    = 2,
  98.     kRegisterD3                    = 3,
  99.     kRegisterD4                    = 8,
  100.     kRegisterD5                    = 9,
  101.     kRegisterD6                    = 10,
  102.     kRegisterD7                    = 11,
  103.     kRegisterA0                    = 4,
  104.     kRegisterA1                    = 5,
  105.     kRegisterA2                    = 6,
  106.     kRegisterA3                    = 7,
  107.     kRegisterA4                    = 12,
  108.     kRegisterA5                    = 13,
  109.     kRegisterA6                    = 14,
  110. /* A7 is the same as the PowerPC SP */
  111.     kCCRegisterCBit                = 16,
  112.     kCCRegisterVBit                = 17,
  113.     kCCRegisterZBit                = 18,
  114.     kCCRegisterNBit                = 19,
  115.     kCCRegisterXBit                = 20
  116. };
  117.  
  118. typedef unsigned short registerSelectorType;
  119.  
  120. /* SizeCodes we use everywhere */
  121.  
  122. enum {
  123.     kNoByteCode                    = 0,
  124.     kOneByteCode                = 1,
  125.     kTwoByteCode                = 2,
  126.     kFourByteCode                = 3
  127. };
  128.  
  129. /* Mixed Mode Routine Records */
  130. typedef unsigned long ProcInfoType;
  131.  
  132. /* Routine Flag Bits */
  133. typedef unsigned short RoutineFlagsType;
  134.  
  135.  
  136. enum {
  137.     kProcDescriptorIsAbsolute    = (RoutineFlagsType)0x00,
  138.     kProcDescriptorIsRelative    = (RoutineFlagsType)0x01
  139. };
  140.  
  141. enum {
  142.     kFragmentIsPrepared            = (RoutineFlagsType)0x00,
  143.     kFragmentNeedsPreparing        = (RoutineFlagsType)0x02
  144. };
  145.  
  146. enum {
  147.     kUseCurrentISA                = (RoutineFlagsType)0x00,
  148.     kUseNativeISA                = (RoutineFlagsType)0x04
  149. };
  150.  
  151. enum {
  152.     kPassSelector                = (RoutineFlagsType)0x0,
  153.     kDontPassSelector            = (RoutineFlagsType)0x08
  154. };
  155.  
  156. enum {
  157.     kRoutineIsNotDispatchedDefaultRoutine = (RoutineFlagsType)0x0,
  158.     kRoutineIsDispatchedDefaultRoutine = (RoutineFlagsType)0x10
  159. };
  160.  
  161. struct RoutineRecord {
  162.     ProcInfoType                    procInfo;                    /* calling conventions */
  163.     SInt8                            reserved1;                    /* Must be 0 */
  164.     ISAType                            ISA;                        /* Instruction Set Architecture */
  165.     RoutineFlagsType                routineFlags;                /* Flags for each routine */
  166.     ProcPtr                            procDescriptor;                /* Where is the thing we’re calling? */
  167.     unsigned long                    reserved2;                    /* Must be 0 */
  168.     unsigned long                    selector;                    /* For dispatched routines, the selector */
  169. };
  170. typedef struct RoutineRecord RoutineRecord;
  171.  
  172. typedef RoutineRecord *RoutineRecordPtr, **RoutineRecordHandle;
  173.  
  174. /* Mixed Mode Routine Descriptors */
  175. /* Definitions of the Routine Descriptor Flag Bits */
  176. typedef UInt8 RDFlagsType;
  177.  
  178.  
  179. enum {
  180.     kSelectorsAreNotIndexable    = (RDFlagsType)0x00,
  181.     kSelectorsAreIndexable        = (RDFlagsType)0x01
  182. };
  183.  
  184. /* Routine Descriptor Structure */
  185. struct RoutineDescriptor {
  186.     unsigned short                    goMixedModeTrap;            /* Our A-Trap */
  187.     SInt8                            version;                    /* Current Routine Descriptor version */
  188.     RDFlagsType                        routineDescriptorFlags;        /* Routine Descriptor Flags */
  189.     unsigned long                    reserved1;                    /* Unused, must be zero */
  190.     UInt8                            reserved2;                    /* Unused, must be zero */
  191.     UInt8                            selectorInfo;                /* If a dispatched routine, calling convention, else 0 */
  192.     short                            routineCount;                /* Number of routines in this RD */
  193.     RoutineRecord                    routineRecords[1];            /* The individual routines */
  194. };
  195. typedef struct RoutineDescriptor RoutineDescriptor;
  196.  
  197. typedef RoutineDescriptor *RoutineDescriptorPtr, **RoutineDescriptorHandle;
  198.  
  199. #define BUILD_ROUTINE_DESCRIPTOR(procInfo, procedure)  \
  200.     {                                \
  201.     _MixedModeMagic,                \
  202.     kRoutineDescriptorVersion,        \
  203.     kSelectorsAreNotIndexable,        \
  204.     0,                                \
  205.     0,                                \
  206.     0,                                \
  207.     0,                                \
  208.     {                                \
  209.     {                                \
  210.     (procInfo),                    \
  211.     0,                                \
  212.     GetCurrentArchitecture(),     \
  213.     kProcDescriptorIsAbsolute |     \
  214.     kFragmentIsPrepared |            \
  215.     kUseNativeISA,                    \
  216.     (ProcPtr)(procedure),            \
  217.     0,                                \
  218.     0,                                \
  219.     },                                \
  220.     },                                \
  221.     }
  222. #define BUILD_FAT_ROUTINE_DESCRIPTOR(m68kProcInfo, m68kProcPtr, powerPCProcInfo, powerPCProcPtr)  \
  223.     {                                \
  224.     _MixedModeMagic,                \
  225.     kRoutineDescriptorVersion,        \
  226.     kSelectorsAreNotIndexable,        \
  227.     0,                                \
  228.     0,                                \
  229.     0,                                \
  230.     1,                                \
  231.     {                                \
  232.     {                                \
  233.     (m68kProcInfo),                \
  234.     0,                                \
  235.     kM68kISA |                        \
  236.     kOld68kRTA,                    \
  237.     kProcDescriptorIsAbsolute |     \
  238.     kUseCurrentISA,                \
  239.     (ProcPtr)(m68kProcPtr),        \
  240.     0,                                \
  241.     0,                                \
  242.     },                                \
  243.     {                                \
  244.     (powerPCProcInfo),                \
  245.     0,                                \
  246.     GetCurrentArchitecture(),     \
  247.     kProcDescriptorIsAbsolute |     \
  248.     kFragmentIsPrepared |            \
  249.     kUseCurrentISA,                \
  250.     (ProcPtr)(powerPCProcPtr),        \
  251.     0,                                \
  252.     0,                                \
  253.     },                                \
  254.     },                                \
  255.     }
  256.  
  257. enum {
  258. /* Calling Convention Offsets */
  259.     kCallingConventionWidth        = 4,
  260.     kCallingConventionPhase        = 0,
  261.     kCallingConventionMask        = 0xF,
  262. /* Result Offsets */
  263.     kResultSizeWidth            = 2,
  264.     kResultSizePhase            = kCallingConventionWidth,
  265.     kResultSizeMask                = 0x30,
  266. /* Parameter offsets & widths */
  267.     kStackParameterWidth        = 2,
  268.     kStackParameterPhase        = (kCallingConventionWidth + kResultSizeWidth),
  269.     kStackParameterMask            = 0xFFFFFFC0,
  270. /* Register Result Location offsets & widths */
  271.     kRegisterResultLocationWidth = 5,
  272.     kRegisterResultLocationPhase = (kCallingConventionWidth + kResultSizeWidth),
  273. /* Register Parameter offsets & widths */
  274.     kRegisterParameterWidth        = 5,
  275.     kRegisterParameterPhase        = (kCallingConventionWidth + kResultSizeWidth + kRegisterResultLocationWidth),
  276.     kRegisterParameterSizePhase    = 0,
  277.     kRegisterParameterSizeWidth    = 2,
  278.     kRegisterParameterWhichPhase = kRegisterParameterSizeWidth,
  279.     kRegisterParameterWhichWidth = 3,
  280. /* Dispatched Stack Routine Selector offsets & widths */
  281.     kDispatchedSelectorSizeWidth = 2,
  282.     kDispatchedSelectorSizePhase = (kCallingConventionWidth + kResultSizeWidth),
  283. /* Dispatched Stack Routine Parameter offsets */
  284.     kDispatchedParameterPhase    = (kCallingConventionWidth + kResultSizeWidth + kDispatchedSelectorSizeWidth),
  285. /* Special Case offsets & widths */
  286.     kSpecialCaseSelectorWidth    = 6,
  287.     kSpecialCaseSelectorPhase    = kCallingConventionWidth,
  288.     kSpecialCaseSelectorMask    = 0x3F0,
  289. /* Component Manager Special Case offsets & widths */
  290.     kComponentMgrResultSizeWidth = 2,
  291.     kComponentMgrResultSizePhase = kCallingConventionWidth + kSpecialCaseSelectorWidth, /* 4 + 6 = 10 */
  292.     kComponentMgrParameterWidth    = 2,
  293.     kComponentMgrParameterPhase    = kComponentMgrResultSizePhase + kComponentMgrResultSizeWidth /* 10 + 2 = 12 */
  294. };
  295.  
  296. #define SIZE_CODE(size)         \
  297.     (((size) == 4) ? kFourByteCode : (((size) == 2) ? kTwoByteCode : (((size) == 1) ? kOneByteCode : 0)))
  298. #define RESULT_SIZE(sizeCode)     \
  299.     ((ProcInfoType)(sizeCode) << kResultSizePhase)
  300. #define STACK_ROUTINE_PARAMETER(whichParam, sizeCode)  \
  301.     ((ProcInfoType)(sizeCode) << (kStackParameterPhase + (((whichParam) - 1) * kStackParameterWidth)))
  302. #define DISPATCHED_STACK_ROUTINE_PARAMETER(whichParam, sizeCode)  \
  303.     ((ProcInfoType)(sizeCode) << (kDispatchedParameterPhase + (((whichParam) - 1) * kStackParameterWidth)))
  304. #define DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(sizeCode)  \
  305.     ((ProcInfoType)(sizeCode) << kDispatchedSelectorSizePhase)
  306. #define REGISTER_RESULT_LOCATION(whichReg)  \
  307.     ((ProcInfoType)(whichReg) << kRegisterResultLocationPhase)
  308. #define REGISTER_ROUTINE_PARAMETER(whichParam, whichReg, sizeCode)  \
  309.     ((((ProcInfoType)(sizeCode) << kRegisterParameterSizePhase) | ((ProcInfoType)(whichReg) << kRegisterParameterWhichPhase)) <<  \
  310.     (kRegisterParameterPhase + (((whichParam) - 1) * kRegisterParameterWidth)))
  311. #define COMPONENT_MGR_RESULT_SIZE(sizeCode)  \
  312.     ((ProcInfoType)(sizeCode) << kComponentMgrResultSizePhase)
  313. #define COMPONENT_MGR_PARAMETER(whichParam, sizeCode)  \
  314.     ((ProcInfoType)(sizeCode) << (kComponentMgrParameterPhase + (((whichParam) - 1) * kComponentMgrParameterWidth)))
  315. #define SPECIAL_CASE_PROCINFO(specialCaseCode)  \
  316.     (kSpecialCase | ((ProcInfoType)(specialCaseCode) << 4))
  317. enum {
  318.     kSpecialCase                = (CallingConventionType)0x0000000F
  319. };
  320.  
  321. enum {
  322. /* all of the special cases enumerated.  The selector field is 6 bits wide */
  323.     kSpecialCaseHighHook        = 0,
  324.     kSpecialCaseCaretHook        = 0,                            /* same as kSpecialCaseHighHook */
  325.     kSpecialCaseEOLHook            = 1,
  326.     kSpecialCaseWidthHook        = 2,
  327.     kSpecialCaseTextWidthHook    = 2,                            /* same as kSpecialCaseWidthHook */
  328.     kSpecialCaseNWidthHook        = 3,
  329.     kSpecialCaseDrawHook        = 4,
  330.     kSpecialCaseHitTestHook        = 5,
  331.     kSpecialCaseTEFindWord        = 6,
  332.     kSpecialCaseProtocolHandler    = 7,
  333.     kSpecialCaseSocketListener    = 8,
  334.     kSpecialCaseTERecalc        = 9,
  335.     kSpecialCaseTEDoText        = 10,
  336.     kSpecialCaseGNEFilterProc    = 11,
  337.     kSpecialCaseMBarHook        = 12,
  338.     kSpecialCaseComponentMgr    = 13
  339. };
  340.  
  341. #if GENERATINGCFM
  342. extern pascal UniversalProcPtr NewRoutineDescriptor(ProcPtr theProc, ProcInfoType theProcInfo, ISAType theISA)
  343.  TWOWORDINLINE(0x7000, 0xAA59);
  344. extern pascal void DisposeRoutineDescriptor(UniversalProcPtr theProcPtr)
  345.  TWOWORDINLINE(0x7001, 0xAA59);
  346. extern pascal UniversalProcPtr NewFatRoutineDescriptor(ProcPtr theM68kProc, ProcPtr thePowerPCProc, ProcInfoType theProcInfo)
  347.  TWOWORDINLINE(0x7002, 0xAA59);
  348. #else
  349. #define DisposeRoutineDescriptor(theProcPtr)
  350. #define NewRoutineDescriptor(theProc, theProcInfo, theISA) ((UniversalProcPtr)theProc)
  351. #endif
  352. #if CFMSYSTEMCALLS
  353. extern long CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...);
  354. extern long CallOSTrapUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...);
  355. #endif
  356.  
  357. #ifdef __CFM68K__
  358. #pragma lib_export off
  359. #endif
  360.  
  361. #if GENERATINGPOWERPC
  362. #pragma options align=reset
  363. #endif
  364.  
  365. #ifdef __cplusplus
  366. }
  367. #endif
  368.  
  369. #endif /* __MIXEDMODE__ */
  370.